//declaring the global variables for the AppPalettes in the lateral menu region
var displayAppPalette;
var lateralAppPalatte;

//global variables for dimensions and DOM inherited from autoSize.js
var w = window;
var d = document;
var e = d.documentElement;
var g = d.getElementsByTagName('body')[0];
var hrh, frh, lrw, vph, hrw, frw, vpw, normalHeight;

var bCrumb;

// --------------- creating navigation AV in header
function AvControllerArtifactFactory()
{}
AvControllerArtifactFactory.prototype.getType = function ()
{
	return "Generic";
}
AvControllerArtifactFactory.prototype.addArtifactBehavior = function (iApplicationDefinition)
{
	return new AvControllerArtifact(iApplicationDefinition);
}

function AvControllerArtifact(applicationDefinition)
{
	this.applicationDefinition = applicationDefinition;
	this.Artifact(this.applicationDefinition);
	this.menuType = ""
}
AvControllerArtifact.prototype.onClick = function (eventObject)
{
	avController_Onclick(this)
}

function bootStrapApplication()
{
	//setting AppPalettes
	displayAppPalette = application.appPalettes['display_app'];
	lateralAppPalatte = application.appPalettes['lateral_app'];

	//set the header_region size, so that designtime may have any size suitable for editing 
	header_region.setOffset(hrh + 'px');
	if(lrw)lateral_region.setOffset(lrw + 'px');
	footer_region.setOffset(frh + 'px');
	//to get the wraparound regionset
	d.getElementById('display_region').parentNode.className += " display-regionset";
	//AV for the header   
	application.importType("wcp.library.util.Artifact");
	application.inherit(AvControllerArtifact, Artifact);
	avController._controllerArtifactFactory = avController.getArtifactFactoryType('AvControllerArtifactFactory');
	avController._controllerArtifactFactory.artifactSchema = cordys.cloneXMLDocument(avSchema.XMLDocument).documentElement;

	//adding allowTransparency to overcome platform bug
	document.getElementById("display_frame").setAttribute("allowTransparency", "true");

	//for window resize
	window.onresize = sizeCorrection;
}

function addPrimaryNavigationMenu(menuDataNodes, bDefaultSelection)
{
	avController._controllerArtifactFactory.addArtifacts(menuDataNodes);
	if (bDefaultSelection)
	{
		avController.getArtifacts()[0].onClick();
		avController.selectArtifactByIndex(0);
	}
}

/*---------------- Generic functionality for opening a click from av and setting a level for breadcrumb---------------*/

function openAppInDisplayFrame(appDef)
{

	var chekframe, levelNode;
	chekframe = cordys.selectXMLNode(appDef, ".//*[local-name()='frame']");
	levelNode = cordys.selectXMLNode(appDef, ".//*[local-name()='level']");

	if (chekframe != null) cordys.setNodeText(appDef, ".//*[local-name()='frame']", "display_frame");
	else cordys.appendXMLNode(cordys.cloneXMLDocument(frameNode.XMLDocument).documentElement, appDef);


	//check for level Node in AppDef. Set as appLevel if present, else create a level node and set
	if (levelNode)
	{
		var level = cordys.getNodeText(levelNode);
		if (level == "") cordys.setNodeText(appDef, ".//*[local-name()='level']", "0");
	}
	else
	{
		cordys.appendXMLNode(cordys.cloneXMLDocument(levelNodeDoc.XMLDocument).documentElement, appDef);
	}
	application.select(appDef, null, frameAutoSize);
}
/*---------------- Generic functionality for opening a click from av and setting a level for breadcrumb ends---------------*/